<?php
require_once("res/const.php");
function saveImage($path, $postid) {
	if ($path == "") {
		return;
	}
	if (!file_exists("res/image/image_$postid.gif")) {
		$ch = curl_init($path);
		$fp = fopen("../../res/image/image_$postid.gif", "wb");
		curl_setopt($ch, CURLOPT_FILE, $fp);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_exec($ch);
		curl_close($ch);
		fclose($fp);
		
		$saveFlag = FALSE;
		require_once("lib/img/simpleImage.php");
		$image = new SimpleImage();
		$image->load("../../res/image/image_$postid.gif");
		if ($image->getWidth() > $IMGTHUMB_WIDTH) {
			$image->resizeToWidth(200);
			$saveFlag = TRUE;
		}
		if ($image->getHeight() > $IMGTHUMB_HEIGHT) {
			$image->resizeToHeight(100);
			$saveFlag = TRUE;
		}
		if ($saveFlag) {
			$image->save("../../res/thumbs/image_$postid-thumb.gif", IMAGETYPE_GIF);
		}
	}
}